package com.xsoft.web.util.excel;



import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.xsoft.logic.model.GameBatchData;


public class ExcelImportUtil {
	/**
	 * 利用poi读取Excel文件
	 * 
	 * @param filePath
	 *            excel文件路径
	 * @throws IOException
	 */
	private static short COLUME_0 = 0;
	private static short COLUME_1 = 1;
	

	private static final Logger logger = LoggerFactory.getLogger(ExcelImportUtil.class);
	
	public static List<GameBatchData> readPay(File file,String gameName,String fuliType,String batchCode) throws IOException {

		FileInputStream fis = new FileInputStream(file); // 根据excel文件路径创建文件流
		POIFSFileSystem fs = new POIFSFileSystem(fis); 			// 利用poi读取excel文件流
		HSSFWorkbook wb = new HSSFWorkbook(fs); 				// 读取excel工作簿
		HSSFSheet sheet = wb.getSheetAt(0); 					// 读取excel的sheet，0表示读取第一个、1表示第二个.....
		List<GameBatchData> list = new ArrayList<GameBatchData>();

		// 获取sheet中总共有多少行数据sheet.getPhysicalNumberOfRows()
		for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) {
			HSSFRow row = sheet.getRow(i + 1); // 取出sheet中的某一行数据
			if (row != null) {
				// 获取该行中总共有多少列数据row.getLastCellNum()
				HSSFCell cell1 = row.getCell(COLUME_1);
				GameBatchData data = new GameBatchData();
				data.setGameName(gameName);
				data.setFuliType(fuliType);
				data.setCodeStr(cell1.getStringCellValue());
				data.setState("1");
				data.setBatchCode(batchCode);
				list.add(data);
			}
			
		}
		
		return list;
	}
	
	
	
	
	
}
